﻿using System;
using System.Web.Mvc;
using Castle.Components.Binder;

namespace System.Web.Mvc.ActiveRecordSupport {
    public class ARFetchAttribute : CustomModelBinderAttribute {
        public ARFetchAttribute(string requestParameterName) {
            RequestParameterName = requestParameterName;
        }

        /// <summary>
        /// The parameter name to be read from the request. The parameter value will 
        /// be used as the primary key value to load the target object instance.
        /// </summary>
        public String RequestParameterName { get; set; }

        /// <summary>
        /// When set to <c>true</c> an instance of
        /// the target type will be created if the record 
        /// is not found. The default is <c>false</c>.
        /// </summary>
        public bool Create { get; set; }

        /// <summary>
        /// When set to <c>true</c>, an exception will be thrown
        /// if the record specified is not found. The default is <c>false</c>.
        /// </summary>
        public bool Required { get; set; }

        /// <summary>
        /// Comma-separated list of lazy associations to eager-fetch, when loading the ActiveRecord object.
        /// </summary>
        public String Eager { get; set; }

        public override IModelBinder GetBinder() {
            return new ARFetcher(new DataBinder().Converter, this);
        }
    }
}